{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    ""
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例1：从物理磁盘的yaml文件中读取prompt数据",
   "id": "202d0d7969088ff0"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-28T20:10:59.587801Z",
     "start_time": "2025-09-28T20:10:58.638012Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from dotenv import load_dotenv\n",
    "from langchain_core.prompts import load_prompt\n",
    "\n",
    "import dotenv\n",
    "\n",
    "dotenv.load_dotenv()\n",
    "prompt = load_prompt(\"prompt.yaml\",encoding=\"utf-8\")\n",
    "print(prompt)\n",
    "print(prompt.format(name=\"年轻人\", what=\"滑稽\"))"
   ],
   "id": "8f1d2f7864ddaaea",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/miniconda3/envs/pyth310/lib/python3.10/site-packages/requests/__init__.py:86: RequestsDependencyWarning: Unable to find acceptable character detection dependency (chardet or charset_normalizer).\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input_variables=['name', 'what'] input_types={} partial_variables={} template='请给{name}讲一个关于{what}的故事'\n",
      "请给年轻人讲一个关于滑稽的故事\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例2：从物理磁盘的json文件中读取prompt数据",
   "id": "6ad71d1a45aaec"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-28T20:13:05.248925Z",
     "start_time": "2025-09-28T20:13:05.241772Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from dotenv import load_dotenv\n",
    "load_dotenv()\n",
    "\n",
    "prompt = load_prompt(\"prompt.json\",encoding=\"utf-8\")\n",
    "print(prompt.format(name=\"张三\",what=\"搞笑的\"))"
   ],
   "id": "6e8d795cff974c9c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请张三讲一个搞笑的的故事。\n"
     ]
    }
   ],
   "execution_count": 3
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
